#region license
# This file is part of Grawlix.
# 
# Grawlix is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
# 
# Grawlix is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public
# License along with Grawlix.  If not, see
# <http://www.gnu.org/licenses/>.
#endregion

"""Recursive disposable testing."""

namespace Grawlix.Meta.Tests.Disposable
import Grawlix.Meta
import NUnit.Framework
import System

[Disposable]
class RecursionA():
	
	def constructor():
		_b = RecursionB(self)
	
	[getter(B)]
	private _b as RecursionB

[Disposable]
class RecursionB():
	
	def constructor(a as RecursionA):
		_c = RecursionC(a)
	
	[getter(C)]
	private _c as RecursionC

[Disposable]
class RecursionC():
	
	def constructor(a as RecursionA):
		_a = a
	
	[getter(A)]
	private _a as RecursionA

[TestFixture]
class RecursionFixture:
	
	[Test]
	def RecursiveDisposalA():
		a = RecursionA()
		b = a.B
		c = b.C
		a.Dispose()
		DisposeTests.Repeated(a)
		DisposeTests.Repeated(b)
		DisposeTests.Repeated(c)
	
	[Test]
	def RecursiveDisposalB():
		a = RecursionA()
		b = a.B
		c = b.C
		b.Dispose()
		DisposeTests.Repeated(a)
		DisposeTests.Repeated(b)
		DisposeTests.Repeated(c)
	
	[Test]
	def RecursiveDisposalC():
		a = RecursionA()
		b = a.B
		c = b.C
		c.Dispose()
		DisposeTests.Repeated(a)
		DisposeTests.Repeated(b)
		DisposeTests.Repeated(c)
